package main;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

public class AISMenuBar extends JMenuBar implements ActionListener {
	AISFrame frame;
	
	public AISMenuBar(AISFrame arg0){
		super();
		frame = arg0;
		JMenu file = new JMenu("File");
		JMenuItem file_new = new JMenuItem("New", KeyEvent.VK_N);
		JMenuItem file_open = new JMenuItem("Open", KeyEvent.VK_O);
		JMenuItem file_save = new JMenuItem("Save", KeyEvent.VK_S);
		JMenuItem file_close = new JMenuItem("Close", KeyEvent.VK_C);
		JMenuItem file_exit = new JMenuItem("Exit", KeyEvent.VK_X);
        file_new.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F2, ActionEvent.ALT_MASK));
        file_open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
        file_save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
        file_close.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, ActionEvent.CTRL_MASK));
        file_exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK));
        file_new.addActionListener(this);
        file_open.addActionListener(this);
        file_save.addActionListener(this);
        file_close.addActionListener(this);
        file_exit.addActionListener(this);
        file_new.setActionCommand("new file");
        file_open.setActionCommand("open file");
        file_save.setActionCommand("save file");
        file_close.setActionCommand("close file");
        file_exit.setActionCommand("exit");
        file.add(file_new);
        file.add(file_open);
        file.add(file_save);
        file.add(file_close);
        file.addSeparator();
        file.add(file_exit);
        setVisible(true);
        this.add(file);
	}
	
	public void actionPerformed(ActionEvent arg0) {
		if(arg0.getActionCommand().equals("exit")){
			frame.close();
		} else if(arg0.getActionCommand().equals("open file")){
			frame.open_file();
		}
	}

}
